package edu.clemson.wcbeck.cft;

import android.app.Activity;
import android.os.Bundle;

public class CFTMyPhotos extends Activity{
	
	  @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.my_media);
	    }
	
	
	
	
	/*private String JPEG_FILE_PREFIX = "CFTmedia";
	private String JPEG_FILE_SUFFIX = ".jpg";
	String PICTURES_DIR = "CFT_Pictures/";
	Button bttnTakePhoto;
	Toast myToast;
	File storageDir;
	CharSequence toastText;
	Bitmap mImageBitmap;
	ImageView mImageView;
	Context contextActivity; PackageManager pm; 
	
    /** Called when the activity is first created. 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_photos);   
        
        bttnTakePhoto = (Button) findViewById(R.id.bttnTakePhoto);  
        mImageView = (ImageView) findViewById(R.id.imgViewPhoto);
        
        contextActivity = this; pm = contextActivity.getPackageManager();
    }
	
    public void onClick(View view) {
    	int actionCode = 99;
    	
    	switch (view.getId()) {
		case R.id.bttnTakePhoto:
			toastText = "You pressed the camera button!";
			myToast = Toast.makeText(this.getApplicationContext(), toastText, Toast.LENGTH_SHORT);
			myToast.show();
	        if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
	    		//boolean hasCamera = true;
	    		actionCode = 0;
	    		
	    		toastText = "You have camera!";
				myToast = Toast.makeText(this.getApplicationContext(), toastText, Toast.LENGTH_SHORT);
				myToast.show();
	    		
	    		//isIntentAvailable(contextActivity, MediaStore.ACTION_IMAGE_CAPTURE);
	    		dispatchTakePictureIntent(actionCode);
	    	}
	        break;
		case R.id.bttnTakeVideo:
			actionCode = 1;
			
			toastText = "You pressed the video button!";
			myToast = Toast.makeText(this.getApplicationContext(), toastText, Toast.LENGTH_SHORT);
			myToast.show();
			
			dispatchTakeVideoIntent(actionCode);
			
    		break;
		case R.id.bttnTakeAudio:
			actionCode = 2;
			
			toastText = "You pressed the audio button!";
			myToast = Toast.makeText(this.getApplicationContext(), toastText, Toast.LENGTH_SHORT);
			myToast.show();
			
			Intent myIntent = new Intent(getBaseContext(), CFTAudioRecord.class);
			startActivityForResult(myIntent, actionCode);
			
			break;
    	}	
    }
    
    public void onActivityResult(int requestCode, int resultCode, Intent data){
    	switch(requestCode){
    	case 0:
    		handleSmallCameraPhoto(data);
    		break;
    	case 1:
    		break;
    	}
    }
    
    private void handleSmallCameraPhoto(Intent intent) {
        Bundle extras = intent.getExtras();
        mImageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(mImageBitmap);
    }
    
    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = 
            new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
        File image = File.createTempFile(
            imageFileName, 
            JPEG_FILE_SUFFIX, 
            getAlbumDir()
        );
        mCurrentPhotoPath = image.getAbsolutePath();
        return image;
    }
    
    private void saveImageFromCamera(Intent intent){
    	storageDir = new File (
    		    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), getAlbumName()
    		);	
    }
    
    private void dispatchTakeVideoIntent(int actionCode) {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        startActivityForResult(takeVideoIntent, actionCode);
        toastText = "Video intent dispatched!";
		myToast = Toast.makeText(this.getApplicationContext(), toastText, Toast.LENGTH_SHORT);
		myToast.show();
    }
    
    private void dispatchTakePictureIntent(int actionCode) {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(takePictureIntent, actionCode);
        toastText = "Camera intent dispatched!";
		myToast = Toast.makeText(this.getApplicationContext(), toastText, Toast.LENGTH_SHORT);
		myToast.show();
		//handleSmallCameraPhoto(takePictureIntent);
    }
    
    /*public static boolean isIntentAvailable(Context context, String action) {
    	switch(actio){
    	case MediaStore.ACTION_IMAGE_CAPTURE:
    		final PackageManager packageManager = context.getPackageManager();
            final Intent intent = new Intent(action);
            List<ResolveInfo> list =
                    packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            return list.size() > 0;
            break;
    	case MediaStore.ACTION_VIDEO_CAPTURE:
    		
    	}
        
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.aboutmenu, menu);
        return true;
    }
    
    public void initMain(){
    	Intent intent = new Intent();
        setResult(RESULT_OK, intent);
        finish();
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.icFavorites: //initAbout();
                                break;
            case R.id.icBack: initMain();
            					break;
            //case R.id.icExit: initExit();
            //					break;
        }
        return true;
    }
    
    public boolean externalMediaAvailable(){
    	boolean mExternalStorageAvailable = false;
    	boolean mExternalStorageWriteable = false;
    	String state = Environment.getExternalStorageState();

    	if (Environment.MEDIA_MOUNTED.equals(state)) {
    	    // We can read and write the media
    	    mExternalStorageAvailable = mExternalStorageWriteable = true;
    	} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    	    // We can only read the media
    	    mExternalStorageAvailable = true;
    	    mExternalStorageWriteable = false;
    	} else {
    	    // Something else is wrong. It may be one of many other states, but all we need
    	    //  to know is we can neither read nor write
    	    mExternalStorageAvailable = mExternalStorageWriteable = false;
    	}
    	
    	return ((mExternalStorageAvailable == true) && (mExternalStorageWriteable == true));
    }*/
}

